<template>
  <div class="business_edit">
    <div class="title">
			<span class="left">添加人员</span>
			<el-button class="add" type="primary" size="small" icon="el-icon-back" @click="$router.back(-1)">返回
			</el-button>
		</div>
    <div class="main">
      <el-form ref="form" :model="form" :rules="rules"  label-width="120px">
        <el-form-item label="网点管理员：" prop="name">
          <el-input v-model="form.name"  placeholder="如：丁某某"></el-input>
        </el-form-item>
		 <el-form-item label="管理员账号：" prop="number">
          <el-input v-model="form.number" placeholder="如：15713840042" :plain="true" maxlength='11' ></el-input>
        </el-form-item>
        <el-form-item label="备注：">
          <el-input maxlength="500" v-model="form.remarks" class="textArea" type="textarea" placeholder=""></el-input>
        </el-form-item>
        <el-button class="btn" type="primary" @click="getDetail">提交</el-button>
      </el-form>
    </div>
  </div>
</template>
<script>
  import titleDiv from './view/titleDiv.vue'
	import {orgManagerAdd} from '../api/getData.js'
  export default {
    name: 'business_edit',
    data: function () {
      return {
        inject:['reload'],
        title:"添加人员管理",
				businessId:'',
        edit:{},
				form:{
					name:'',
					number:''
        },
        rules: {
          name:[{required: true, message: '请输入网点管理员 ', trigger: ['blur']}],
          number:[{required: true,message:'请输入管理员账号 '}]
        }
      }
    },
    components:{
      titleDiv
     
    },
    created() {
		}, // 创建时
    beforeMount: function () {}, // 挂载之前
    mounted: function () {
    }, // 挂载之后
    beforeUpdate: function () {}, // 数据更新时调用,在渲染之前
    updated: function () {}, // 数据更新后,渲染后调用(禁止)
    beforeDestroy: function () {}, // 实例销毁前调用,解绑中间层的数据传输
	destroyed: function () {}, // 实例销毁后调用
	

    methods: {
      checkTrue(){
        console.log('dcs',this.form.number)
        let str = this.form.number
        isPoneAvailable(str)
          
      },
			getDetail(){
        function isPoneAvailable(str) {
              var myreg=/^[1][3,4,5,7,8,9][0-9]{9}$/;
              if (!myreg.test(str)) {
                  return false;      
              } else { 
                  return true;       
              }
       }
       let str = this.form.number
        if(isPoneAvailable(str)){
            orgManagerAdd({
            "personName":this.form.name,
            "Logincode":this.form.number,
            "remarks":this.form.remarks
          }).then((res) =>{
            console.log(res.data)
            if(res.data.code === 0){
              this.$message({
                message:res.data.msg,
                type: 'success'
              });
            var _this = this;
            setTimeout(function() {
              _this.$router.push ("/orgPeople/orgPeopleIndex");
            },1000);
            }else{
              this.$message.error(res.data.msg)
            }
          }).catch((error) =>{
            console.log(error)
          })
        }else{
            this.$message.error('检查手机号是否输入有误');
        }
				
			}
		} // 函数
  }
</script>
<style lang='scss'>
.title {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 64px;
			line-height: 64px;
			background: #fff;
			overflow: hidden;
			text-align: left;
			padding: 0 20px;
			color: #333437;
			font-size: 16px;
		}
  .business_edit {
    box-sizing: border-box;
    .main{
      background: #fff;
      width: 100%;
      margin-top: 3%;
      padding: 5% 20%;
      .textArea{
        textarea{
          min-height: 240px!important;
        }

      }
      .el-form-item__label{
        font-weight: bold;
      }
      .btn{
        width: 120px;
        height:32px;
        line-height: 1px;
        margin-left: 80px;
      }
    }
  }
</style>

